package com.ruoyi.project.cms.notice.service;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.text.Convert;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.ruoyi.project.cms.notice.mapper.CmsNoticeMapper;
import com.ruoyi.project.cms.notice.domain.CmsNotice;

import java.util.List;

/**
 *com.ruoyi.project.cms.notice.service
 *作者：lh
 描述:
 *时间:2020-05-17
 */
@Service
public class CmsNoticeServiceImpl implements CmsNoticeService{

    @Resource
    private CmsNoticeMapper cmsNoticeMapper;

    @Override
    public int deleteByPrimaryKey(int nid) {
        return cmsNoticeMapper.deleteByPrimaryKey(nid);
    }

    @Override
    public int insert(CmsNotice record) {
        return cmsNoticeMapper.insert(record);
    }

    @Override
    public int insertSelective(CmsNotice record) {
        return cmsNoticeMapper.insertSelective(record);
    }

    @Override
    public CmsNotice selectByPrimaryKey(int nid) {
        return cmsNoticeMapper.selectByPrimaryKey(nid);
    }

    @Override
    public int updateByPrimaryKeySelective(CmsNotice record) {
        return cmsNoticeMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(CmsNotice record) {
        return cmsNoticeMapper.updateByPrimaryKey(record);
    }

    @Override
    public List<CmsNotice> selectNoticeList(CmsNotice cmsNotice) {
        return cmsNoticeMapper.selectNoticeList(cmsNotice);
    }

    @Override
    public String checkNoticeNameUnique(CmsNotice cmsNotice) {
        int tid = StringUtils.isNull(cmsNotice.getNid()) ? -1: cmsNotice.getNid();
        CmsNotice info = cmsNoticeMapper.checkNoticeNameUnique(cmsNotice.getNname());
        if (StringUtils.isNotNull(info))
        {
            return "1";
        }
        return "0";
    }

    @Override
    public int deleteNoticeByIds(String ids) {
        Integer[] nid = Convert.toIntArray(ids);
        for (int n:nid){
            cmsNoticeMapper.deleteByPrimaryKey(n);
        }
        return 1;
    }


    @Override
    public List<CmsNotice> selectByTp(int tid) {
        return cmsNoticeMapper.selectByTp(tid);
    }

}
